package com.nineclock.attendance.controller;

import com.nineclock.api.attendance.AttendGroupControllerApi;
import com.nineclock.attendance.dto.AttendGroupDTO;
import com.nineclock.attendance.service.AttendGroupService;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class AttendGroupController implements AttendGroupControllerApi {

    @Autowired
    private AttendGroupService attendGroupService;

    @Override
    @GetMapping("/attendGroup")
    public Result<PageResult<AttendGroupDTO>> queryAttendGroupPage(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResult<AttendGroupDTO> pageResult = attendGroupService.queryAttendGroupPage(page, pageSize);
        return Result.success(pageResult);
    }


    @Override
    @PostMapping("/attendGroup")
    public Result addAttendGroup(@RequestBody AttendGroupDTO attendGroupDTO) {
        attendGroupService.addAttendGroup(attendGroupDTO);
        return Result.success();
    }


    @Override
    @GetMapping("/getAttendGroupByUserId")
    public Result<AttendGroupDTO> queryAttendGroup() {
        AttendGroupDTO attendGroupDTO = attendGroupService.queryAttendGroup();
        return Result.success(attendGroupDTO);
    }
}
